const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const Weather = sequelize.define('Weather', {
  weather_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    field: 'weather_id'
  },
  city_id: { 
    type: DataTypes.INTEGER, 
    allowNull: false,
    field: 'city_id'
  },
  temperature: { 
    type: DataTypes.FLOAT, 
    allowNull: false 
  },
  description: { 
    type: DataTypes.STRING, 
    allowNull: false 
  },
  date: { 
    type: DataTypes.DATE, 
    allowNull: false 
  }
}, {
  tableName: 'Weather',
  timestamps: false
});

// models/Weather.js
Weather.associate = (models) => {
  Weather.belongsTo(models.City, { 
    foreignKey: 'city_id',
    targetKey: 'city_id'  // 指定关联的目标键
  });
};

module.exports = Weather;